<?php

namespace addons\qingdongams\model;

use think\Model;

/**
 *费用详情
 */
class ConsumeDetail Extends Model {


    // 表名,不含前缀
    protected $name = 'qingdongams_consume_detail';
	// 开启自动写入时间戳字段
	protected $autoWriteTimestamp = false;
    // 追加属性
    protected $append = [
        'imgList',
        'fileList',
    ];


    //获取附件
    public function getImgListAttr($value, $data) {

        $files  = explode(',', $data['file_ids']??'');
        $result = [];
        foreach ($files as $fid) {
            if ($fid) {
                $result[]=['url'=> cdnurl(File::getUrl($fid), true),'id'=>$fid] ;
            }
        }

        return $result;
    }
    //获取附件列表
    public function getFileListAttr($value, $data)
    {
        $files  = explode(',', $data['other_files']??'');
        $result = [];
        foreach ($files as $fid) {
            if ($fid) {
                $file=File::get($fid);
                $result[] = ['id'=>$file['id'],'name'=>$file['name'],'url'=>cdnurl($file['file_path'], true)];
            }
        }

        return $result;
    }


    //详情
    public function consume()
    {
        return $this->belongsTo(Consume::class, 'consume_id', 'id')->setEagerlyType(0);
    }



}
